import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import { visualizer } from "rollup-plugin-visualizer"
import AutoImport from 'unplugin-auto-import/vite' // 自动导入配置的模块
import Components from 'unplugin-vue-components/vite' // 自动导入组件的模块
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' // 自动导入 Element Plus 的 Api
import ElementPlus from 'unplugin-element-plus/vite' // 自动导入 Element Plus 的 style
import vue from '@vitejs/plugin-vue'
import path from "path"
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    vue(),
    visualizer(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    ElementPlus({})
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      "@api": path.resolve(__dirname, "src/api")
    }
  },
  server: {
    proxy: {
      '/myApi': {
        target: 'https://xiaoyueyue.com.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/myApi/, ''), // 重写请求路径，去掉 '/api' 前缀
      },
    }
  },
  build: {
    rollupOptions: {
      manualChunks: {
        axios: ["axios"],
        "vue-router": ["vue-router"],
        vue: ["vue"],
      },
    },
  },
})
